
<?php
	require_once("connect_sql.php");
	
	$id = $_GET['id'];
	$project_id = 0;

	if($ret = mysql_query("select * from writeRecord where id='$id'")) {
		$ret = mysql_fetch_array($ret);
		$project_id = $ret['project'];
		$version = $ret['recordVersion'];
		$quantity = $ret['quantity'];
		
		$board = '';
		$customer = '';
		$business = '';
		$str = '';
		if($ret = mysql_query('select board,customer,business from project where id='.$project_id)) {
			$ret = mysql_fetch_array($ret);
			$board = $ret['board'];
			$customer = $ret['customer'];
			$business = $ret['business'];
			$str .= $board.'-';
		}
		if($ret = mysql_query('select abbreviate from customer where id='.$customer)) {
			$ret = mysql_fetch_array($ret);
			$str .= $ret['abbreviate'].'-';
		}
		$str .= $business.'(';
		$str .= $version.',';
		$str .= $quantity.')';
	}
	
	$sql = 'delete from writeRecord where id='.$id;
	if(!mysql_query($sql)) {
		echo "";
	} else {
		mysql_query('insert into log (user, nickname, action, date, content, sqlStr) values("'.$_COOKIE['username'].'", "'.$_COOKIE['nickname'].'", "删除", "'.date("Y-m-d").'", "'.$str.'", "'.$sql.'")');
		
		$sql = 'select sum(quantity) as num from writeRecord where project="'.$project_id.'"';
		$result = mysql_query($sql);
		if(!$result) echo mysql_error();
		while($row = mysql_fetch_array($result)) {
			echo '<tr><td class="td5"></td>';
			printf("<td class=\"tdLeft\"><span>量产总数：</span>%.1f K</td>", $row['num']);
			echo '</tr>';
			break;
		}
		
		$sql = "select * from writeRecord where project=\"$project_id\" order by recordDate DESC";
		$result = mysql_query($sql);
		if(!$result) echo mysql_error();
		
		$i = 1;
		while($row = mysql_fetch_array($result)) {
			printf("<tr>\n");
			printf("\t<td class='td5'><span>%d.</span></td>\n", $i++);
			printf("\t<td class='td6'>版本：%s</td>\n", $row['recordVersion']);
			printf("\t<td class='td7'>数量：%s</td>\n", $row['quantity']);
			printf("\t<td class='td8'>时间：%s</td>\n", $row['recordDate']);
			printf("\t<td class='td9'><button class='button deleteBtn' onClick='onDeleteRecordClick(%d)'>删除</button></td>\n", $row['id']);
			printf("</tr>\n");
		}
	}

?>